package cn.Mmovie.servlet;

import cn.Mmovie.bean.Cinema;
import cn.Mmovie.service.CinemaService;
import cn.Mmovie.service.impl.CinemaServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AdminCinemaModifyServlet", value = "/admin/cinema_modify")
public class AdminCinemaModifyServlet extends HttpServlet {
    private CinemaService cinemaService=new CinemaServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("---------CinemaModify--------");
        if (request.getParameter("id")==null||request.getParameter("id")==""){
            request.setAttribute("failMsg","没有指定需要修改的电影院，请重试！");
            request.getRequestDispatcher("/admin/cinema_list").forward(request,response);
        }
        Integer id=Integer.parseInt(request.getParameter("id"));
        System.out.println(id);
        Cinema cinema=cinemaService.queryCinemaById(id);
        if (cinema!=null){
            request.setAttribute("cinema",cinema);
            request.getRequestDispatcher("/WEB-INF/page/main/cinema_modify.jsp").forward(request,response);
        }else {
            request.setAttribute("failMsg","需要修改的电影院不存在，请重试！");
            request.getRequestDispatcher("/admin/cinema_list").forward(request,response);
        }
    }
}
